package linker.plugin;

import linker.account.ManageAccount;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.Vector;

/**
 * 
 * @version linker 0.93
 * @author Jianfeng jianfeng.linker@gmail.com
 * 
 */
public class PluginInfo {

	private static Properties p = new Properties();

	public static Vector getInfo(File file) {
		Vector<Object> v = new Vector<Object>();
		
		if (!file.isDirectory())
			return null;

		String infoFile = file.getAbsolutePath()
				+ ManageAccount.getFileSeparator() + "info";

		try {
			p.clear();
			p.load(new FileInputStream(infoFile));
		} catch (FileNotFoundException e) {
			try {
				new File(infoFile).createNewFile();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		if(p.size()==0){
			p.put("Name", file.getName());
			v.add(file.getName());
			p.put("Use count", "0");
			v.add("0");
			p.put("Status", "Enable");
			v.add("Enable");
			
			try {
				p.store(new FileOutputStream(infoFile),"Info");
			} catch (FileNotFoundException e1) { 
				e1.printStackTrace();
			} catch (IOException e1) { 
				e1.printStackTrace();
			}
		}else{
			v.add(p.get("Name"));
			v.add(p.get("Use count"));
			v.add(p.get("Status"));
		}
		
		return v;
	}

}
